package com.situ.project1.controller;

import com.situ.project1.service.impl.UpLoadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping(value = "/api/uploads", produces = "application/json;charset=utf-8")
public class UploadFileApi {
    private UpLoadFileService uploadFileService;

    @Autowired
    public void setUploadFileService(UpLoadFileService uploadFileService) {
        this.uploadFileService = uploadFileService;
    }
    /**
     * 上传头像
     *
     * @return 成功与否
     */
    @PostMapping("/avatar")
    public Map<String, Object> uploadAvatar(MultipartFile file) {
        String url = this.uploadFileService.uploadAvatar(file);
        return Map.of("success", true, "url", url);
    }
}
